﻿
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace A.M.Joint_Search
{
    public class BaseOrmRepository : IBaseOrmRepository
    {
        private readonly ISqlSugarClient _client;
        public BaseOrmRepository(ISqlSugarClient client)
        {
            _client = client;
        }

        /// <summary>
        /// 两表查询，
        /// </summary>
        /// <typeparam name="T1">左表</typeparam>
        /// <typeparam name="T2">右表</typeparam>
        /// <param name="joinExp">联表方式，联表字段（主外键关系）</param>
        /// <param name="selectExp">联表查询的结果</param>
        /// <param name="isWhere">是否需要查询条件</param>
        /// <param name="whereExp">条件查询</param>
        /// <returns></returns>
        public async Task<List<T>> getJoinList<T1, T2,T>(Expression<Func<T1, T2, JoinQueryInfos>> joinExp, Expression<Func<T1, T2, T>> selectExp, bool isWhere = false, Expression<Func<T1, T2, bool>> whereExp = null)
        {

            var list =  await _client.Queryable<T1, T2>(joinExp).WhereIF(isWhere, whereExp).Select(selectExp).ToListAsync();
            return list;
        }


        

    }
}
